
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
    <meta name="generator" content="Jekyll v3.8.5">
    <title><?php echo $this->htmlTitle();?></title>

    <!-- Bootstrap core CSS -->
    <link href="/dist/bootstrap-4.3/css/bootstrap.min.css" rel="stylesheet">

    <style>
        html,
        body {
            height: 100%;
        }

        body {
            display: -ms-flexbox;
            display: flex;
            -ms-flex-align: center;
            align-items: center;
            padding-top: 40px;
            padding-bottom: 40px;
            background-color: #f5f5f5;
        }

        .form-signin {
            width: 100%;
            max-width: 330px;
            padding: 15px;
            margin: auto;
        }
        .form-signin .checkbox {
            font-weight: 400;
        }
        .form-signin .form-control {
            position: relative;
            box-sizing: border-box;
            height: auto;
            padding: 10px;
            font-size: 16px;
        }
        .form-signin .form-control:focus {
            z-index: 2;
        }
        .form-signin input[type="text"] {
            margin-bottom: -1px;
            border-bottom-right-radius: 0;
            border-bottom-left-radius: 0;
        }
        .form-signin input[type="password"] {
            margin-bottom: 10px;
            border-top-left-radius: 0;
            border-top-right-radius: 0;
        }
        .bd-placeholder-img {
            font-size: 1.125rem;
            text-anchor: middle;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }

        @media (min-width: 768px) {
            .bd-placeholder-img-lg {
                font-size: 3.5rem;
            }
        }
    </style>
    <!-- Custom styles for this template -->
<!--    <link href="signin.css" rel="stylesheet">-->
</head>
<body class="text-center">
<form class="form-signin">
    <img class="mb-4" src="/dist/bootstrap-4.3/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72">
    <h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
    <label for="inputUsername" class="sr-only">用户名：</label>
    <input type="text" id="inputUsername" name="username" class="form-control" placeholder="Username" required autofocus>
    <label for="inputPassword" class="sr-only">密 码：</label>
    <input type="password" id="inputPassword" name="password" class="form-control" placeholder="Password" required>
    <div class="checkbox mb-3">
        <label>
            <input type="checkbox" name="remember" value=""> 记住我
        </label>
    </div>
    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
    <p class="mt-5 mb-3 text-muted">&copy; 2017-2019</p>
</form>
<!-- Mainly scripts -->
<script src="/dist/js/jquery-3.1.1.min.js?v=<?php echo config('version.core');?>"></script>
</body>
</html>
<script>
    var login = new function () {
        var I = this,
            authUrl = '/login',
            returnUrl = '/',
            form = $("form.form-signin");

        I.init = function () {
            form.submit(function (event) {
                I.submit(event);
            });
        };
        I.submit = function (e) {
            e.preventDefault();
            var loginInfo = {};
            $('input', form).each(function (i, v) {
                var $v = $(v),
                    name = $v.attr('name'),
                    type = $v.attr('type'),
                    val;
                if (type === 'checkbox') {
                    val = $v.is(":checked") ? 1 : 0;
                } else {
                    val = $.trim($v.val());
                }
                if (type !== 'checkbox') {
                    if (!val || typeof name === 'undefined') {
                        $v.focus();
                        return;
                    }
                }
                loginInfo[name] = val;
            });

            if ($.isEmptyObject(loginInfo)) {
                return I.msg('登录参数错误.');
            }
            I.auth(loginInfo);
            return false;
        };
        I.auth = function (data) {
            $.ajax({
                url: authUrl,
                data: data,
                type: 'POST',
                success: function (res) {
                    if (!res || res.stat !== 200) {
                        return I.msg(res.msg);
                    }
                    window.location.href = res.returnUrl ? res.returnUrl : returnUrl;
                },
                error: function (res) {
                    console.log(res);
                    I.msg('login error');
                }
            });
        };
        I.msg = function (msg) {
            return alert(msg);
        }
    };

    $(function(){
        login.init();
    });
</script>